package com.yuneec.droneservice.command;

import com.MAVLink.yuneec.msg_mav_rc_cmd_ack;
import com.yuneec.droneservice.model.ControllerLocation;
import com.yuneec.droneservice.request.IResponse;

/**
 * Created by gjw on 2017/3/27.
 */

public class SetControllerGPS extends BaseCommand {
    private final short[] data;

    /**
     * @param usePhoneGPS 是否使用手机gps，如果使用手机gps则所传gps数值将替换遥控器gps，如果不用手机gps则使用遥控器gps
     * @param location    手机gps数值
     */
    public SetControllerGPS(boolean usePhoneGPS, ControllerLocation location) {
        super(MAV_RC_COMMAND.MAV_RC_CMD_SET_GPS);
        data = new short[18];
        data[0] = (short) (usePhoneGPS ? 1 : 0);
        intToUIntArray(data, 1, (int) (location.longitude * 1e7));
        intToUIntArray(data, 5, (int) (location.latitude * 1e7));
        shortToUIntArray(data, 9, (short) (location.altitude * 100));
        data[11] = (short) location.satelliteCount;
        shortToUIntArray(data, 12, (short) location.accuracy);
        shortToUIntArray(data, 14, (short) location.speed);
        shortToUIntArray(data, 16, (short) location.angle);
    }

    @Override
    protected short[] body() {
        return data;
    }

    @Override
    public IResponse toResponse(msg_mav_rc_cmd_ack ack) {
        int code = ack.code;
        return new IResponse(ids(), code);
    }
}
